package com.cdjf.mapper;

import com.cdjf.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

    @Select("select * from tb_emp")
    public List<Emp> empList();

    @Delete("delete from tb_emp where id = #{id}")
    public int delete(Integer id);

    public int batchDelete(List<Integer> ids);

    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into tb_emp(username, name, gender, image, job, entry_date, dept_id, create_time, update_time)" +
                  " values(#{username}, #{name}, #{gender}, #{image}, #{job}, #{entryDate}, #{deptId}, now(), now());")
    public int insert(Emp emp);

    //更新员工
    @Update ("update tb_emp set username = #{username}, name = #{name}, gender = #{gender}, image = #{image}," +
            " job = #{job}, entry_date = #{entryDate}, dept_id = #{deptId}, update_time = #{updateTime} where id = #{id}")
    public void update(Emp emp);

    public void updateEmp(Emp emp);

    //根据ID查询员工
    @Select("select * from tb_emp where id = #{id}")
    public Emp getById(Integer id);

    public Emp selectById(Integer id);

//    @Select("select id, username, password, name, gender, image, job, entry_date entryDate," +
//            " dept_id deptId, create_time createTime, update_time updateTime from tb_emp where id = #{id}")
//    public Emp getById(Integer id);

    //万案二:通过@Results，@Result注解手动映射封装
//    @Results({
//            @Result(column = "dept_id", property = "deptId"),
//            @Result(column = "entry_date", property = "entryDate"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
//    @Select("select * from tb_emp where id = #{id}")
//    public Emp getById(Integer id);

    //条件查询员工
    @Select("select * from tb_emp where name like concat('%', #{name}, '%') and gender = #{gender} and " +
            "entry_date between #{begin} and #{end} order by update_time desc ")
    public List<Emp> search(String name, byte gender, LocalDate begin , LocalDate end);

    public List<Emp> searchList(String name, byte gender, LocalDate begin , LocalDate end);
}
